package com.shop.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shop.pojo.pms.Pms_Attr_Group;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

//分组表
public interface Pms_Attr_Group_Mapper extends BaseMapper<Pms_Attr_Group> {
//根据分类id和分页的页码来查询当前分类下的分组信息
@Select("select pag.attr_group_id,pag.attr_group_name,pag.sort,pag.descript,pag.icon,paar.catelog_id from pms_attr_group as pag inner join pms_attr_attrgroup_relation as paar on pag.attr_group_id=paar.attr_group_id where paar.catelog_id=#{catalogId} group by pag.attr_group_id")
<E extends IPage<Pms_Attr_Group>> E selectPageGroup(E page, @Param("catalogId") Integer catalogId);
//查询没有被使用过的分组信息
    @Select("select * from pms_attr_group where attr_group_id not in(select pag.attr_group_id from pms_attr_group as pag inner join pms_attr_attrgroup_relation as paar on pag.attr_group_id=paar.attr_group_id  group by pag.attr_group_id)")
    <E extends IPage<Pms_Attr_Group>> E selectNotPageGroup(E page);
    //查询当前分类下的分组信息
@Select("select * from pms_attr_group where attr_group_id in(select distinct(attr_group_id) from pms_attr_attrgroup_relation where catelog_id=#{catelogId})")
    List<Pms_Attr_Group> findAllGroupByCatelogId(Long catelogId);
//根据属性来查询当前属性下的分组名称
    @Select("select pag.* from pms_attr_attrgroup_relation as paar inner join pms_attr_group as pag on paar.attr_group_id=pag.attr_group_id ${ew.customSqlSegment}")
      List<Pms_Attr_Group> findAllGroupByattrId(@Param("ew") Wrapper<Pms_Attr_Group> queryWrapper);

}
